import 'package:situation/app/router/router_name.dart';
import 'package:situation/app/theme/app_theme.dart';
import 'package:situation/app/theme/gaps.dart';
import 'package:situation/resources/assets.dart';
import 'package:situation/widgets/mk_card_container.dart';
import 'package:situation/widgets/mk_list_cell_item.dart';
import 'package:situation/widgets/mk_load_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class SystemSettingIndexPage extends StatefulWidget {
  const SystemSettingIndexPage({Key? key}) : super(key: key);

  @override
  State<SystemSettingIndexPage> createState() => _SystemSettingIndexPageState();
}

class _SystemSettingIndexPageState extends State<SystemSettingIndexPage> {
  final controller = Get.find<SystemSettingIndexController>();
  final state = Get.find<SystemSettingIndexController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: TDNavBar(
          title: '设置',
        ),
        body: ListView(
          children: <Widget>[
            _buildNav(),
            Gaps.vGap24,
            TDButton(
              text: '退出登录',
              isBlock: true,
              theme: TDButtonTheme.primary,
              onTap: controller.logout,
            )
          ],
        ));
  }

  _buildNav() {
    return MkCardContainer(
      padding: EdgeInsets.symmetric(horizontal: AppTheme.iDefaultPadding / 2),
      margin: EdgeInsets.symmetric(
          horizontal: AppTheme.iDefaultPadding,
          vertical: AppTheme.iDefaultPadding / 2),
      borderRadius: AppTheme.iBorderRadius,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [

          Obx(() => MkListCellItem(
                value: '关于',
                textIcon: MkLoadImage(Assets.settingAbout, width: 20),
                ext: Text(
                  '版本号 v${state.version}',
                  style: TextStyle(fontSize: 12, color: Colors.grey),
                ),
                press: () => {
                Get.toNamed(RouterName.appAbout)
                },
              )),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<SystemSettingIndexController>();
    super.dispose();
  }
}
